package test.core.safe;

import java.util.List;
import java.util.Map;

import hyl.core.MyFun;
import hyl.core.db.MyDB;

import hyl.core.io.MyPath;
import hyl.core.run.MyRun;
import hyl.core.safe.MyBase64;
import hyl.core.safe.RsaCert;
import hyl.core.safe.MySecret;
import jnr.ffi.Struct.int16_t;
import test.My;

public class DemoCert {

	public static void main(String[] args) throws Exception {
		DemoCert demo = new DemoCert();
		// demo.测试数据库();
		// demo.测试路径();
		// demo.测试rsa();
		// demo.测试签名();
		 demo. 验证签名();
		// demo.读取证书属性();
		//demo.读取p12证书属性();
	}

	public void print(String key, String msg) {
		System.out.println(key + "=" + msg);
	}

	public void 测试数据库() {

		// TODO Auto-generated method stub
		My.getInstance();
		MyDB db = My.createDb();
		List<Map<String, Object>> list = db.queryList("select * from user", null);
		for (Map<String, Object> m : list) {
			System.out.println(m.get("Host"));
		}

	}

	public void 测试路径() {
		print("getClassesPath", MyPath.getPathOfClassLoader(this.getClass().getClassLoader()));
		print("getJarPath", MyPath.getPathOfJar(this.getClass()));
		print("getPathOfClass", MyPath.getPathOfClass(this.getClass()));
		print("getPathOfPro", MyPath.getPathOfPro());
		// print("exini",exini.get("11-2"));
	}




	public void 验证签名() throws Exception {
		RsaCert mc = RsaCert.getInstance();

		mc.create密钥对();
		StringBuilder sb = new StringBuilder("这些年你过得好吗？");
		for (int i=0;i<900000;i++) {
			sb.append("真心蠢比从V聊天从V想你想存");
		}
		String s=sb.toString();
		long n1=MyRun .f测速(()->{
			String s1;
			try {
				s1 = mc.f私钥签名(s);
				MyFun.print("====签名验证结果1=====\n 签名", s1,"\n",mc.f公钥验签(s, s1));
			} catch (Exception e) {
				e.printStackTrace();
			}		
		});

		MyFun.print(s.getBytes().length/1024,n1);
	}

	public void 读取证书属性() throws Exception {
		RsaCert mc = RsaCert.getInstance();
		 mc.load密钥库("test库", "");
		mc.load证书X509("D:\\keystore\\ssl\\client\\client.crt");

	}



	public void 用证书验证签名() throws Exception {
	}

}
